/**
 * Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.altuure.yagdao.dao;

import java.util.List;

import com.altuure.yagdao.GenericDAO;
import com.altuure.yagdao.YFetch;
import com.altuure.yagdao.YMethod;
import com.altuure.yagdao.YMethodType;
import com.altuure.yagdao.YOperator;
import com.altuure.yagdao.YPage;
import com.altuure.yagdao.YParameter;
import com.altuure.yagdao.model.OrderItem;

public interface OrderItemDAO extends GenericDAO<OrderItem, Long> {

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findByProductCategory(
            @YParameter(value = "product.category", operator = YOperator.EQUAL) long category);

    @YMethod(type = YMethodType.CRITERIA, select = { "id", "product.id", "product.name", "order.id",
            "order.customer.id", "order.customer.name" })
    List<Object[]> findSelected(@YParameter(value = "product.category", operator = YOperator.EQUAL) long category);

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findByProductMaxPrice(@YParameter(value = "product.price", operator = YOperator.LT) double maxPrice);

    @YMethod(type = YMethodType.CRITERIA)
    @YFetch("product")
    List<OrderItem> findByProductMaxPriceFetch(
            @YParameter(value = "product.price", operator = YOperator.LT) double maxPrice);

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findByProductMaxPriceAndCategory(
            @YParameter(value = "product.price", operator = YOperator.LT) double maxPrice,
            @YParameter(value = "product.category", operator = YOperator.EQUAL, not = true) long category);

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findByCustomerCity(
            @YParameter(value = "order.customer.city", operator = YOperator.EQUAL) String city);

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findByCustomerCityAndMaxPrice(
            @YParameter(value = "order.customer.city", operator = YOperator.EQUAL) String city,
            @YParameter(value = "product.price", operator = YOperator.LT) double maxPrice);

    @YMethod(type = YMethodType.CRITERIA)
    @YFetch({ "product", "order", "order.customer" })
    List<OrderItem> findByCustomerCityAndMaxPrice2(
            @YParameter(value = "order.customer.city", operator = YOperator.EQUAL) String city,
            @YParameter(value = "product.price", operator = YOperator.LT) double maxPrice);

    @YMethod(type = YMethodType.CRITERIA, orderBy = "order.customer.name")
    @YFetch({ "product", "order", "order.customer" })
    List<OrderItem> findComplex(@YParameter(value = "order.customer.city", operator = YOperator.EQUAL) String city,
            @YParameter(value = "product.price", operator = YOperator.LT) double maxPrice);

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findByCity(@YParameter(value = "order.customer.city", operator = YOperator.EQUAL) String city,
            YPage addOrder);

    @YMethod(type = YMethodType.CRITERIA)
    List<OrderItem> findOrder(YPage addOrder);

}
